<template>
  <div id="app">
    <div>
      <div style="display: inline-block" v-for="ele in arr" :key="ele">
        <input type="checkbox"  @click="flag(ele)"/>
        <span>{{ele}}</span>
      </div>
      <p>你选中的元素, 累加的值和为:{{total}}</p>
    </div>
  </div>
</template>

<script>
export default {
data(){
  return{
    arr: [9, 15, 19, 25, 29, 31, 48, 57, 62, 79, 87],
    newArr:[]
  }
},
methods:{
  flag(ele){
    let i = this.newArr.findIndex(item=> item === ele)
    console.log(i);
    if(i === -1){
        this.newArr.push(ele)
    }else{
       this.newArr.splice(i,1)
      
    }
    console.log(this.newArr);
  }
},
computed:{
  total(){
  return this.newArr.reduce((t,c)=> t + c ,0)
  }
}
}
</script>

<style>

</style>